package cmd

import (
	"gitee.com/crack007/goose"
	"gitee.com/crack007/goose/core/ws"
	"github.com/crack007/go-im/src/module/ws/handle"
	"github.com/spf13/cobra"
)

func NewWsCommand() *goose.ModuleBuilder {

	sessionBuilder := ws.NewSessionBuilder()
	imServerHandle := handle.NewImServerHandle(sessionBuilder)
	builder := ws.NewServerBuilder(imServerHandle, sessionBuilder)
	builder.EnableDebugFlag().EnableConfigFlag().EnablePprof()
	builder.SetServerName("wsServer")
	builder.RegisterFlag(func(cobraCmd *cobra.Command) {
		cobraCmd.PersistentFlags().BoolVar(&imServerHandle.IsSlave, "slave", false, "slave模式")
		cobraCmd.PersistentFlags().StringVar(&imServerHandle.MasterIp, "masterip", "", "master节点IP")
		cobraCmd.PersistentFlags().Uint16Var(&imServerHandle.MasterPort, "masterport", 0, "master节点端口")
	})
	return goose.NewModuleBuilder(builder).SetName("ws").SetDesc("ws服务模块")
}
